<?php


class coder
{
	private $_dir;
	private $_compiler;
	public function __construct( $dir='' )
	{
		if( !empty( $dir ) ){
			$this->_dir = $dir;
		}else{
			$dir = dirname(dirname( __FILE__ ));
			$this->_dir = $dir.DS.'app';			
		}
		$this->_compiler[] = new replace;
	}
	
	public function run()
	{
		$this->compilerDir( $this->_dir );
	}
	
	private function compilerDir( $dir )
	{
		$dh  = opendir($dir);
		while (false !== ($filename = readdir($dh))) {
			if( $filename!= '.' &&  $filename != '..' ){
				if( is_dir($dir.DS.$filename) )
					$this->compilerDir( $dir.DS.$filename );
				else{
					$this->compileFile($dir.DS.$filename);
				}
			}
		}
		
	}
	
	private function compileFile( $file )
	{
		
		$content = file_get_contents( $file );
		foreach($this->_compiler as $_compiler){
			$content = $_compiler->compile($content);
		}
		file_put_contents( $file,$content );
		return;
	}
	
	
	
	
	
	
}